﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.admin.product
{
    public partial class auction_bid_info : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int productid = ChangeHope.WebPage.PageRequest.GetQueryInt("w_d_productid");
                if (productid > 0)
                {
                    this.lbProductName.Text = ProductName(productid.ToString())+"的出价记录";
                }
                GetList();
            }
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        protected void GetList()
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            YXShop.BLL.Product.Product_Auction_Bid data = new YXShop.BLL.Product.Product_Auction_Bid();
            ChangeHope.DataBase.DataByPage dataPage = data.GetListByPage();

            YXShop.BLL.Product.ProductAuction pabll = new YXShop.BLL.Product.ProductAuction();
            YXShop.Model.Product.ProductAuction pamodel = null;
            //第一步先添加表头
            table.AddHeadCol("10%", "拍卖编号");
            table.AddHeadCol("10%", "客户姓名");
            table.AddHeadCol("15%", "订单编号");
            table.AddHeadCol("20%", "商品名称");
            table.AddHeadCol("5%", "价格");
            table.AddHeadCol("10%", "拍卖日期");
            table.AddHeadCol("10%", "状态");
            table.AddHeadCol("20%", "操作");
            table.AddRow();
            //添加表的内容
            if (dataPage.DataReader != null)
            {
                while (dataPage.DataReader.Read())
                {
                    string productid = dataPage.DataReader["productid"].ToString();
                    pamodel = pabll.GetModelID(Convert.ToInt32(productid));

                    table.AddCol("No." + dataPage.DataReader["id"].ToString());
                    table.AddCol(dataPage.DataReader["username"].ToString());
                    table.AddCol(dataPage.DataReader["orderno"].ToString());

                    table.AddCol(ProductName(productid));
                    table.AddCol(dataPage.DataReader["price"].ToString());
                    table.AddCol(dataPage.DataReader["datetime"].ToString());
                    table.AddCol(dataPage.DataReader["state"].ToString());
                    if (pamodel != null)
                    {
                        if (Convert.ToDateTime(pamodel.EndTime) <= System.DateTime.Now)
                        {
                            if (data.maxValues("price", productid) == dataPage.DataReader["price"].ToString())
                            {
                                table.AddCol("<span style='color:#666666'>删除</span>&nbsp;<a href=''>转成拍卖订单</a>");
                            }
                            else
                            {
                                table.AddCol("<a href='#' onclick='Del({0})'>删除</a>&nbsp;<span style='color:#666666'>转成拍卖订单</span>");
                            }
                        }
                    }
                    else
                    {

                        table.AddCol("<span style='color:#666666'>删除</span>&nbsp;<span style='color:#666666'>转成拍卖订单</span>");
                    }
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            this.Literal1.Text = view;
        }
        protected string ProductName(string productid)
        {
            string reStr = string.Empty;
            string str = "暂无商品";
            if (!string.IsNullOrEmpty(productid))
            {
                YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
                YXShop.Model.Product.ProductInfo model = bll.GetModel(Convert.ToInt32(productid));
                if (model != null)
                {
                    reStr = model.pro_Name;
                }
                if (!string.IsNullOrEmpty(reStr))
                {
                    str = reStr;
                }
            }
            return str;
        }
    }
}
